package com.example.service.impl;

import com.example.chat.UDPClient;
import com.example.pojo.Chat;
import com.example.service.ChatService;
import com.example.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ChatServiceImpl implements ChatService {
    @Override
    public void chat(Chat chat) {

        Claims claims = JwtUtils.parseJWT(chat.getJwt());
        Integer id = (Integer)claims.get("id");
        String studentID = (String) claims.get("studentID");
        String name = (String) claims.get("name");
        log.info(id.toString()+studentID.toString()+name.toString());

        UDPClient udpClient = null;
        try {
            udpClient = new UDPClient();
        } catch (Exception e) {
            e.printStackTrace();
        }

        udpClient.sendMessage(chat);
    }
}
